package com.gxc.mq;

import com.alibaba.fastjson.JSON;
import com.gxc.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 生产者.
 *
 * @author GongXincheng
 * @since 2019-08-23 00:28
 */
@Slf4j
@Component
public class Demo1_Provider {

    @Resource
    private AmqpTemplate amqpTemplate;

    public void send() {
        User user = new User(1, "gxc", "admin", 23, new Date(), "desc");
        log.info("send message to rabbitmq, content [{}]", JSON.toJSONString(user));
        amqpTemplate.convertAndSend("hello", user);
    }

}
